<?php
/**
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

This is called only at creating a new component and not any where else..
called from build_component_xml.php
*/
$component_id=$_GET['id'];
$page_xml = $_GET['page_xml'];

if(!isset($semf_root) )
{
	$semf_root = '../';
	// Define that we are returning XML content & not to cache:
	header('Content-Type: text/xml');
	header('Cache-control: no-cache');
}

$doc = new DOMDocument();
$doc->load($page_xml);
$doc->validate();
$the_component = $doc->getElementById($component_id);

//here we assumes containers are just empty.. since it is even yet to create ( from this page:))
$containers = $the_component-> getElementsByTagName('container');

echo "
		var elem = null;
		var component = null;
		var parentContainer = null;
		var yuiTarget = null;
	";
foreach ( $containers as $container )
{
	$child_container_id =  $container-> getAttribute('id');
	echo "
		elem = document.getElementById('$child_container_id');
		component = SEMF.pageDesigner.components['childs']['$component_id'];
		parentContainer = component.container;
		yuiTarget = new YAHOO.util.DDTarget('$child_container_id', COMPONENT_DND_GROUP);
		
		SEMF.pageDesigner.addContainer( elem, '$child_container_id',  parentContainer, yuiTarget);
	";
}
		
?>